<template>
    <div>
        <square-button icon="el-icon-platform-eleme" slot="reference" :title="title" v-on="$listeners"  v-bind="$attrs" @click="getDocumentQrcode" v-if="show"></square-button>
        <base-dialog :is-view="true" :visible.sync="visible" v-if="visible" title="印章二维码" width="300px">
            <img :src="qrcode" style="width: 100%"/>
        </base-dialog>
    </div>
</template>
<script>
    import SquareButton from "../SquareButton";
//    import schoolSignature from "@/api/officialDocument/schoolSignature/index"
    import eventBus from "@/utils/eventBus";
    import BaseDialog from "../../../Common/BaseDialog";
    export default {
        name:"QRCodeButton",
        components: {BaseDialog, SquareButton},
        props:{
            title:{
                type:String,
                default:"印章二维码"
            },
        },
        data(){
          return{
              id:"",
              act_state_id:0,
              creator:"",
              userName: localStorage.getItem("username"),
              qrcode:"",
              is_stamp:"",
              visible:false
          }
        },
        created() {
            eventBus.$on("showQrcodeButton",(data)=>{
                this.id = data.app_id
                this.act_state_id = data.act_state_id
                this.creator = data.creator
                this.is_stamp = data.is_stamp
                console.log("data",data)
            })
        },
        computed:{
          show(){
              return this.creator==this.userName&&this.act_state_id==4
          },
        },
        methods:{
            getDocumentQrcode(){
                console.log("this.is_stamp)",this.is_stamp)
                if (this.is_stamp) {
                    // schoolSignature.getDocumentQrcodeById(this.id).then(res => {
                    //     this.qrcode = res.data.url
                    //     this.visible = true
                    // })
                } else {
                    // schoolSignature.getDocumentQrcode({id:this.id}).then(res=>{
                    //     this.msgSuccess(res.msg)
                    // })
                }
            }
        }
    }
</script>
<style scoped>
</style>
